package proyecto.BusinessLogic;

import java.util.List;

import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import proyecto.DataAccessObject.RegistroIngresoDAORemote;
import proyecto.EntityBeans.RegistroIngreso;

@Stateless
@Remote(RegistroIngresoBLRemote.class)
public class RegistroIngresoBL implements RegistroIngresoBLRemote {

	RegistroIngresoDAORemote registroIngresoDAORemote;
	
	public int save(RegistroIngreso registroIngreso) {	
		
		try
		{
			Context context = new InitialContext();
			registroIngresoDAORemote = (RegistroIngresoDAORemote) context.lookup("RegistroIngresoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
			
		return registroIngresoDAORemote.save(registroIngreso); //alta de registroIngreso		
		
	}
		
	public RegistroIngreso findById(int id) {
		try
		{
			Context context = new InitialContext();
			registroIngresoDAORemote = (RegistroIngresoDAORemote) context.lookup("RegistroIngresoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
			
		return registroIngresoDAORemote.findById(id);
		
	}
	
		
	public void merge(RegistroIngreso registroIngreso) {
		try
		{
			Context context = new InitialContext();
			registroIngresoDAORemote = (RegistroIngresoDAORemote) context.lookup("RegistroIngresoDAO/remote");
			registroIngresoDAORemote.merge(registroIngreso);
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}	
		
	}
	
		
	public List findAll() {		
		try
		{
			Context context = new InitialContext();
			registroIngresoDAORemote = (RegistroIngresoDAORemote) context.lookup("RegistroIngresoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
		return registroIngresoDAORemote.findAll();
	}
	
	public List findByIdList(int id)
	{	     
		try
		{
			Context context = new InitialContext();
			registroIngresoDAORemote = (RegistroIngresoDAORemote) context.lookup("RegistroIngresoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
	    return registroIngresoDAORemote.findByIdList(id);
	}
	
		
	public void remove(int idRegistroIngreso){	
		try
		{
			Context context = new InitialContext();
			registroIngresoDAORemote = (RegistroIngresoDAORemote) context.lookup("RegistroIngresoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
		registroIngresoDAORemote.remove(idRegistroIngreso);
	}
	
	public void refresh(RegistroIngreso registroIngreso){
		try
		{
			Context context = new InitialContext();
			registroIngresoDAORemote = (RegistroIngresoDAORemote) context.lookup("RegistroIngresoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
		registroIngresoDAORemote.refresh(registroIngreso);
	}
}
